<template>
  <div class="app-container home">
    <div class="fr">
      <el-form :inline="true" :model="formInline" class="">
        <el-form-item label="文件名称">
          <el-input
            v-model="formInline.standardName"
            clearable
            placeholder="请输入"
            size="small"
          ></el-input>
        </el-form-item>
        <el-form-item label="文件编号">
          <el-input
            v-model="formInline.standardNo"
            clearable
            placeholder="请输入"
            size="small"
          ></el-input>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="handleSearch" size="small"
            >搜索</el-button
          >
          <el-button type="primary" plain @click="handleReset" size="small"
            >重置</el-button
          >
        </el-form-item>
      </el-form>
    </div>
    <el-table v-loading="loading" :data="tableData">
      <el-table-column
        label="序号"
        type="index"
        width="50"
        :index="indexMethod"
      >
      </el-table-column>
      <el-table-column prop="standardNo" label="文件编号"> </el-table-column>
      <el-table-column prop="standardName" label="文件名称"> </el-table-column>
      <el-table-column prop="standardVersion" label="文件版本" />
      <el-table-column prop="createTime" label="最近引用时间" />
    </el-table>

    <el-pagination
      class="p20 fr"
      v-if="total > 0"
      :background="true"
      :current-page.sync="queryParams.pageNum"
      :page-size.sync="queryParams.pageSize"
      :layout="'total, sizes, prev, pager, next, jumper'"
      :page-sizes="[10, 30, 50, 100]"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handlepageNumChange"
    />
  </div>
</template>

<script>
import { getReferenceRecordList } from "@/api/business";
export default {
  name: "ReferenceFiles",
  data() {
    return {
      formInline: {
        docName: "",
        status: "",
      },
      queryParams: {
        pageNum: 1,
        pageSize: 10,
      },
      loading: false,
      total: 0,
      tableData: [],
    };
  },
  methods: {
    indexMethod(index) {
      return (
        (this.queryParams.pageNum - 1) * this.queryParams.pageSize + index + 1
      );
    },
    async onSearch() {
      try {
        this.loading = true;
        const res = await getReferenceRecordList({
          ...this.queryParams,
          ...this.formInline,
        });
        this.tableData = res.data.list;
        this.total = res.data.count;
      } catch (error) {
        console.debug(error);
      } finally {
        this.loading = false;
      }
    },
    handleReset() {
      this.formInline = {};
      this.onSearch();
    },
    handleSearch() {
      this.queryParams.pageNum = 1;
      this.onSearch();
    },
    handleSizeChange(val) {
      if (this.queryParams.pageSize * val > this.total) {
        this.queryParams.pageNum = 1;
      }
      this.onSearch();
    },
    handlepageNumChange() {
      this.onSearch();
    },
  },
  mounted() {
    this.handleSearch();
  },
};
</script>
